import 'package:flutter/material.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';
import 'package:get/get_rx/src/rx_types/rx_types.dart';

import 'package:mobile_vpn/common/cpn/cpn_view_state.dart';

import 'package:mobile_vpn/common/cpn/sliver_app_bar.dart';

import 'package:mobile_vpn/pages/user_page/user_set/user_set_login.dart';
import 'package:mobile_vpn/theme/color_palettes.dart';

import '../../../router/routers.dart';

class UserSetPage extends CpnViewState<UserSetLogic> {
  UserSetPage({Key? key}) : super(key: key, bindViewState: false);
  @override
  Widget buildBody(BuildContext context) {
    return Scaffold(
      backgroundColor: ColorPalettes.instance.background,
      body: CustomScrollView(
        slivers: <Widget>[
          commonSliverAppBar(
            title: '账户设置',


          ),
          SliverList(
            delegate: SliverChildListDelegate([
              _buildListTile(
                leading: Icons.lock_outline,
                title: '修改密码',
                subtitle: '您可以随时修改账户密码，保障账户安全。',
                onTap: () {
                  AppRoutes.jumpPage(AppRoutes.setPasswordPage);

                },
              ),
              _buildListTile(
                leading: Icons.exit_to_app,
                title: '退出账户',
                subtitle: '退出账户后，账户内的时长将全部给到当前设备。',
                onTap: () {
                  // 处理退出账户点击事件
                  _showLogoutDialog(context);
                },
              ),
              _buildListTile(
                leading: Icons.delete_outline,
                title: '注销账户',
                subtitle: '注销后您的账户数据将被永久清空，请谨慎操作。',
                onTap: () {
                  // 处理注销账户点击事件
                  _showDeleteAccountDialog(context);
                },
                isLast: true,
              ),
            ]),
          ),
        ],
      ),
    );
  }

  Widget _buildListTile({
    required IconData leading,
    required String title,
    required String subtitle,
    required VoidCallback onTap,
    bool isLast = false,
  }) {
    return ListTile(
      leading: Icon(
        leading,
        color: ColorPalettes.instance.firstText,
        size: 40.w,
      ),
      title: Text(
        title,
        style: TextStyle(
          color: ColorPalettes.instance.firstText,
          fontSize: 32.sp,
        ),
      ),
      subtitle: Text(
        subtitle,
        style: TextStyle(
          color: ColorPalettes.instance.secondText,
          fontSize: 24.sp,
        ),
      ),
      trailing: Icon(
        Icons.arrow_forward_ios,
        color: ColorPalettes.instance.thirdText,
        size: 40.w,
      ),
      onTap: onTap,
    );
  }

  void _showLogoutDialog(BuildContext context) {
    showDialog(
      context: context,
      builder: (BuildContext context) {
        return AlertDialog(
          title: Text('确认退出账户？'),
          content: Text('您确定要退出当前账户吗？'),
          actions: <Widget>[
            TextButton(
              child: Text('取消'),
              onPressed: () {
                Navigator.of(context).pop();
              },
            ),
            TextButton(
              child: Text('确认'),
              onPressed: () {
                // 执行退出账户的操作
                // Navigator.of(context).pop();
                // Navigator.pushReplacement(
                //   context,
                //   MaterialPageRoute(builder: (context) => UserLoginPage()),
                // );
              },
            ),
          ],
        );
      },
    );
  }

  void _showDeleteAccountDialog(BuildContext context) {
    showDialog(
      context: context,
      builder: (BuildContext context) {
        return AlertDialog(
          title: Text('确认注销账户？'),
          content: Text('您确定要注销当前账户吗？此操作不可逆！'),
          actions: <Widget>[
            TextButton(
              child: Text('取消'),
              onPressed: () {
                Navigator.of(context).pop();
              },
            ),
            TextButton(
              child: Text('确认'),
              onPressed: () {
                // 执行注销账户的操作
                Navigator.of(context).pop();
                // 这里可以添加注销账户的具体逻辑
                // Navigator.pushReplacement(
                //   context,
                //   MaterialPageRoute(builder: (context) => UserLoginPage()),
                // );
              },
            ),
          ],
        );
      },
    );
  }
}
